package org.dr.springmvcdemo.webclient;

import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

public class test {
    public static void main(String[] args) {


        // WebClient webClient = WebClient.create();
        //
        // Mono<String> mono = webClient
        //         .get() // GET 请求
        //         .uri("http://jsonplaceholder.typicode.com/posts/1")  // 请求路径
        //         .retrieve() // 获取响应体
        //         .bodyToMono(String.class); //响应数据类型转换
        //
        // System.out.println(mono.block());


        WebClient webClient = WebClient.create("http://jsonplaceholder.typicode.com");

        Mono<String> mono = webClient
                .get() // GET 请求
                .uri("/posts/1")  // 请求路径
                .retrieve() // 获取响应体
                .bodyToMono(String.class); //响应数据类型转换

        System.out.println(mono.block());

    }
}
